library(survey)
library(dplyr)
library(stargazer)
library(performance)

## creating Model for Table 3.4 
# model: multivariate model based on demographics, logit specification, DV: Q17a

summary(factor(df$Q17A))
df$Q17A_REP <- NA
summary(df$Q17A_REP)
df$Q17A_REP[df$Q17A == 1 | df$Q17A == 3] <- 0
df$Q17A_REP[df$Q17A == 2] <- 1

summary(df$Q17A_REP)
summary(factor(df$Q17A_REP))
summary(df$weight2)

## Create weighted survey design object
w2_design <-
  svydesign(
    id = ~ 1,
    weights = ~ weight2,
    data = df
  )

## creating Model for Table 3.4
# model: multivariate model based on demographics, logit specification, DV: 
fig3.4_mod <- svyglm(Q17A_REP ~ dem + rep + ideo3 + 
                       male + white + black + hispanic + asian + 
                       income5 + dem*EDUC5 + rep*EDUC5 + unemployed + married + 
                       silent + boomer + genx + millen + 
                       activeduty + vet + social + family + 
                       midwest + south + west + 
                       catholic + christian + norelig +
                       city + rural + 
                       A2 + A3 + A4 + A5 + A6 + A7 + A8,
                     family = binomial(link = "logit"),
                     design = w2_design)

summary(fig3.4_mod)
check_collinearity(fig3.4_mod)
stargazer(fig3.4_mod)